/*
 * @Descripttion:
 * @version:
 * @Date: 2021-04-20 11:06:21
 * @LastEditors: huzhushan@126.com
 * @LastEditTime: 2021-07-26 13:37:30
 * @Author: huzhushan@126.com
 * @HomePage: https://huzhushan.gitee.io/vue3-element-admin
 * @Github: https://github.com/huzhushan/vue3-element-admin
 * @Donate: https://huzhushan.gitee.io/vue3-element-admin/donate/
 */
import request from '@/utils/request'
import router, { asyncRoutes, fixedRoutes } from '@/router'

// 获取菜单
export const GetMenus = params => {
  return request({
    url: '/api/menus',
    method: 'get',
    params,
  })

  // const generateMenus = async () => {
  //   // // 方式一：只有固定菜单
  //   // const menus = getFilterMenus(fixedRoutes)
  //   // setMenus(menus)
  //
  //   // 方式二：有动态菜单
  //   // 从后台获取菜单
  //   const { code, data } = await GetMenus()
  //
  //   if (+code === 200) {
  //     // 添加路由之前先删除所有动态路由
  //     asyncRoutes.forEach(item => {
  //       router.removeRoute(item.name)
  //     })
  //     // 过滤出需要添加的动态路由
  //     const filterRoutes = getFilterRoutes(asyncRoutes, data)
  //     filterRoutes.forEach(route => router.addRoute(route))
  //
  //     // 生成菜单
  //     const menus = getFilterMenus([...fixedRoutes, ...filterRoutes])
  //     setMenus(menus)
  //   }
}
